/**
 * @file lv_ledstrip.c
 *
 */

/*********************
 *      INCLUDES
 *********************/

#include "lv_ledstrip.h"
#include "../lv_obj_ex/lv_obj_ex.h"
#include "lvgl.h" //led.h

#if LV_USE_LEDSTRIP

/*********************
 *      DEFINES
 *********************/
#define MY_CLASS        (&lv_toolbar_class)

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/

lv_obj_t * lv_ledstrip_create(lv_obj_t * parent)
{
    lv_obj_t * toolbar = lv_toolbar_create(parent);
    return toolbar;
}

void lv_ledstrip_set_count(lv_obj_t * ledstrip,  uint8_t count)
{
    uint8_t org_count = lv_obj_get_child_count(ledstrip);
    if(count > org_count){
        for(count = count - org_count; count > 0; count--){
            lv_obj_t * led  = lv_led_create(ledstrip);
            lv_led_off(led);
        }
    }
    else if(count < org_count){
        uint8_t pos = count - 1;
        for(count = org_count - count; count > 0; count--){
            lv_obj_delete(lv_obj_get_child(ledstrip, pos));
        }
    }
}

void lv_ledstrip_off_all(lv_obj_t * ledstrip)
{
    LV_ASSERT_OBJ(ledstrip, MY_CLASS);
    lv_obj_set_all_attrib0(ledstrip, lv_led_off);
}

void lv_ledstrip_off(lv_obj_t * ledstrip, uint8_t pos)
{
    LV_ASSERT_OBJ(ledstrip, MY_CLASS);
    lv_obj_t * led  = lv_obj_get_child(ledstrip, pos);
    lv_led_off(led);
}

void lv_ledstrip_on(lv_obj_t * ledstrip, uint8_t pos)
{
    LV_ASSERT_OBJ(ledstrip, MY_CLASS);
    lv_obj_t * led  = lv_obj_get_child(ledstrip, pos);
    lv_led_on(led);
}

/**********************
 *   STATIC FUNCTIONS
 **********************/

#endif /*LV_USE_LEDSTRIP*/
